Total Complexity | 2 |
Total Lines | 17 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | import { Inject } from '@nestjs/common'; |
||
7 | |||
8 | export class CanUserAccessToSchool { |
||
9 | constructor( |
||
10 | @Inject('IUserRepository') |
||
11 | private readonly userRepository: IUserRepository, |
||
12 | @Inject('ISchoolUserRepository') |
||
13 | private readonly schoolUserRepository: ISchoolUserRepository |
||
14 | ) {} |
||
15 | |||
16 | public async isSatisfiedBy(school: School, userId: string): Promise<boolean> { |
||
17 | const user = await this.userRepository.findOneById(userId); |
||
18 | if (!user) { |
||
19 | return false; |
||
20 | } |
||
21 | |||
22 | return user.getRole() === UserRole.PHOTOGRAPHER || |
||
23 | (await this.schoolUserRepository.findOneByUserAndSchool(user, school)) instanceof SchoolUser; |
||
24 | } |
||
26 |